package com.manxi.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Set;

@Component
@Slf4j
public class DIshTask {

    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * 处理菜品redis缓存信息的方法
     */
//    @Scheduled(cron = "0 0/5 * * * ?") //每分钟执行一次
//    @Scheduled(cron = "0 0 1 * * ?") //每天凌晨一点执行一次
    @Scheduled(cron = "0 0 0 ? * MON") //每周一凌晨1点执行一次
    public void clearDishCache() {
        log.info("处理菜品redis缓存信息:{}", LocalDateTime.now());
        Set keys = redisTemplate.keys("dish_*");
        redisTemplate.delete(keys);
    }
}
